package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.OrderDetail;
import com.fyt.ZhongYaoApp.pojo.Orders;
import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.dto.OrdersDTO;
import com.fyt.ZhongYaoApp.pojo.dto.OrdersSubmitDTO;
import com.fyt.ZhongYaoApp.pojo.vo.OrderSubmitVO;
import com.fyt.ZhongYaoApp.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户购买全部购物车
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {

        System.out.println("用户下单，参数为：" + ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 查看订单详情
     * @param ordersDTO
     * @return
     */
    @PostMapping("/showDetail")
    public Result<List<OrderDetail>> showDetail(@RequestBody OrdersDTO ordersDTO) {

        List<OrderDetail> list = orderService.showDetail(ordersDTO);
        return Result.success(list);
    }

    /**
     * 查看用户订单列表
     * @return
     */
    @PostMapping("/list")
    public Result<List<Orders>> list() {

        List<Orders> list = orderService.orderList();
        return Result.success(list);
    }
}
